home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / prolog / sbprolog / amiga / c_src2_5.zoo / sub_inst.c < prev    next >
C/C++ Source or Header  |  1989-08-16  |  4KB  |  158 lines

  1. /************************************************************************
  2. *                                    *
  3. * The SB-Prolog System                            *
  4. * Copyright SUNY at Stony Brook, 1986; University of Arizona, 1987    *
  5. *                                    *
  6. ************************************************************************/
  7.  
  8. /*-----------------------------------------------------------------
  9. SB-Prolog is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY.  No author or distributor
  11. accepts responsibility to anyone for the consequences of using it
  12. or for whether it serves any particular purpose or works at all,
  13. unless he says so in writing.  Refer to the SB-Prolog General Public
  14. License for full details.
  15.  
  16. Everyone is granted permission to copy, modify and redistribute
  17. SB-Prolog, but only under the conditions described in the
  18. SB-Prolog General Public License.   A copy of this license is
  19. supposed to have been given to you along with SB-Prolog so you
  20. can know your rights and responsibilities.  It should be in a
  21. file named COPYING.  Among other things, the copyright notice
  22. and this notice must be preserved on all copies. 
  23. ------------------------------------------------------------------ */
  24.  
  25.  
  26. /* sub_inst.c */
  27. /* modification history 
  28.     07/16/89 RNK - Modified signals for Amiga,
  29.              added flag AMIGA, define it for amiga port 
  30.  
  31.  
  32. RNK = Nick Kline
  33. */
  34. #include <signal.h>
  35. #include "sim.h"
  36. #include "aux.h"
  37.  
  38. #ifndef AMIGA
  39.    struct sigvec vec;
  40. #endif
  41.  
  42.  
  43. /* set interrupt code in reg 2 and return ep of interrupt handler */
  44. byte *set_intercode(intcode)
  45. int intcode;
  46. {
  47.     if (!is_PRED(interrupt_psc)) {
  48.         quit("Interrupt handler not defined\n");
  49.     }
  50.     gregc(2) = makeint(intcode);
  51.     return(get_ep(interrupt_psc));
  52.  
  53. }
  54.  
  55. intercept_proc()
  56. {
  57.     if (interrupt_code == 0) {
  58.     interrupt_code = 1;
  59.     }
  60.     else exit(2);
  61. }
  62.  
  63. arm_intercept()
  64. {
  65.     /* set up interrupt routine */
  66. #ifdef AMIGA
  67.     signal(SIGINT,intercept_proc); /* branch on ^C */
  68. #else
  69.     vec.sv_handler = intercept_proc;
  70.     vec.sv_mask = 0;
  71.     vec.sv_onstack = 0;
  72.     sigvec(2, &vec, 0);
  73. #endif
  74. }
  75. /****************************************************************************/
  76.  
  77.  
  78. callv_sub()   /* arg from register 1 */
  79. {
  80.     word term;
  81.     register pw top;
  82.     short int   i;
  83.     struct psc_rec *psc_ptr;
  84.     char    s1[256];
  85.  
  86.     term = gregc(1);
  87.     cvlab: switch ((int)(term & TAGMASK)) {
  88.     case FREE: 
  89.         nderef (term, cvlab);
  90.     case NUM: 
  91.         printf("illegal call\n");
  92.         Fail0;
  93.         return;
  94.     case LIST: 
  95.         psc_ptr = list_psc;
  96.         term -= 4;
  97.         goto cstst;
  98.     case CS: 
  99.         psc_ptr = get_str_psc(term);
  100.       cstst:
  101.         if (interrupt_code > 0)
  102.         {    interrupt_code = 0;
  103.         pcreg = set_intercode(1);
  104.         return;
  105.         };
  106.         /* call code */
  107.         if (is_PRED(psc_ptr) || is_DYNA(psc_ptr))
  108.         pcreg = get_ep(psc_ptr);
  109.         else
  110.         {    pcreg = set_intercode(0);
  111.         return;
  112.         }
  113.         untag(term);
  114.         for (i = 1; i <= get_arity(psc_ptr); ++i)
  115.         gregc(i) = follow((pw) term + i);
  116.     }
  117.     if (hitrace == 1)
  118.     {   printf("callv: ");
  119.         writepname(stdout, get_name(psc_ptr), get_length(psc_ptr));
  120.         printf("        (");
  121.         for (i = 1; i <= get_arity(psc_ptr); i++)
  122.         {    printf(" ");
  123.         printterm(gregc(i), 1);
  124.         }
  125.         printf(")\n");
  126.     }
  127. }
  128.  
  129. /****************************************************************************/
  130.  
  131.  
  132. /* builds the current call onto the heap and points reg 1 to it, 
  133.    and puts the interrupt number in reg 2 */
  134.  
  135. build_call(psc)
  136. struct psc_rec *psc;
  137. {
  138.     register word callstr, arg;
  139.     register int i;
  140.     register pw top;
  141.  
  142.     callstr = (word)hreg;    /* save addr of new structure rec */
  143.     new_heap_node((word)psc); /* set str psc ptr */
  144.     for ( i=1; i<=get_arity(psc); i++) {
  145.     arg = gregc(i);
  146.     bldc: if ((arg & 3) == 0) {
  147.         nderef(arg, bldc);
  148.         follow(arg) = (word)hreg;
  149.         pushtrail(arg);
  150.         new_heap_free;
  151.         }
  152.     else new_heap_node(arg);
  153.     }
  154.     gregc(1) = callstr | CS_TAG; /* ptr to new structure on heap */
  155. }
  156.  
  157.  
  158.